<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Captcha;
class AuthController extends Controller
{
	// protected $registerView = 'home/auth.register'; #默认注册模板
    //  protected $loginView = 'home/auth.login'; #默认登陆表单
     protected $redirectPath = '/'; # 登陆成功后的跳转方向
	 
    //  protected $redirectAfterLogout = 'home/'; # 默认退出后跳转页
    //  protected $loginPath = 'home/auth/login'; # 默认登陆URL
    //  protected $username = 'home/name'; #与password字段配合登陆的字段,name,email,mobile都可以 
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
		$messages = [
				'required'     => ':attribute 不是必填字段',
				'email'    => ':attribute 邮箱的格式不对或邮箱已注册过',
				'size'   => ':attribute 手机号不是11位',
                'password' => ':attribute 密码至少6位',
			];
		
		
	
        return Validator::make($data, [
            'name' => 'required|max:255',
             
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
			'mobile' => 'required|size:11',
			'verify' => 'required',
        ],$messages);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
		//dd($data);
        $user = User::create([
            'name' => $data['name'],
			
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
			'mobile' => $data['mobile'],
        ]);
		/* //插入附加表   user_info   uid = $user->id
		$user_info=[];
		$user_info['sex']=$data['sex'];
		$user_info['age']=$data['age'];
		$user_info['uid']=$user->id;
		//DB::table('user_info')->insert($user_info);*/
		 return $user; 
		//dd($user);
    }
	/*
    * 生成验证码
    */
    public  function  Verify()
    {
       return  Captcha::src();
    }

   /*
    * 验证验证码
    */

    public  function VerifyCode($code)
    {
        return Captcha::check($code);
    }
}
